<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
   // $fields=array('id','name');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_sns_manage',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$v['bid']=pdo_getcolumn('jy_sns_board',array('id'=>$v['bid']),'title');
		$v['name']=pdo_getcolumn('core_members',array('id'=>$v['mid']),'nickname');
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'版主管理'),
			array('op'=>'edit','title'=>'添加版主'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'name','title'=>'版主','type'=>'string'),
			array('name'=>'bid','title'=>'所属板块','type'=>'string'),
			
			
		)),
	);
	$return['enabled']=array('0'=>'禁用','1'=>'启用');
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_sns_manage',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'版主设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'版主管理'),
			array('op'=>'edit','title'=>'添加版主')
		),
		'edit'=>array(
			array('type'=>'choose','title'=>'选择版主','name'=>'mid','action'=>'get_member','choose_title'=>'选择版主'),
			array('name'=>'bid','title'=>'所属板块','type'=>'select','options'=>'bid'),
			)
			);
	//$return['enabled']=array('0'=>'禁用','1'=>'启用');
	//$return['isrecommand']=array('0'=>'否','1'=>'是');
	$return['bid']=pdo_getall('jy_sns_board',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['mid']){
		exi('请选择版主');
	}
	$data=array_fields(array('bid','mid'),$postdata);
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_sns_manage',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_sns_manage',$data);
				exi('添加成功！','','list');
			}
			}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_sns_manage',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_sns_manage',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>